package cn.yangliu.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 作者 杨柳
 * 创建时间 2017-08-29 01:02
 */
@Component
@Aspect
@Order(Integer.MIN_VALUE) //最后进入 最先出
public class LogAspect extends AbstractAspect {

    @Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)" +
            "||@annotation(org.springframework.web.bind.annotation.DeleteMapping)" +
            "||@annotation(org.springframework.web.bind.annotation.PutMapping)" +
            "||@annotation(org.springframework.web.bind.annotation.PostMapping)" +
            "||@annotation(org.springframework.web.bind.annotation.GetMapping)")
    public void advice() {
    }

    @Around("advice()")
    public Object logAspect(ProceedingJoinPoint joinPoint) throws Throwable {
        Object object;
        try {
            object = joinPoint.proceed();
        } catch (Throwable e) {
            doRecord(e,joinPoint);
            throw e;
        }
        return object;
    }


}
